home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / crobots7 / cornerkl.r < prev    next >
Text File  |  1988-07-20  |  3KB  |  94 lines

  1. /* Corner Killer */
  2. /* By Eric Maddox */
  3. /* moves to the center and shoots into the corners */
  4. main ()
  5. {
  6. int dam; /* damage */
  7. if (loc_x()<500)
  8.   {
  9.    while (loc_x() < 400)
  10.         drive (0,100);                                     /* goto x center */
  11.    while (loc_x() < 440)
  12.         drive (0,50);
  13.    drive (0,0);                                                     /* stop */
  14.   }  
  15.   else                                       /* if robot is right of center */
  16.       {
  17.        while (loc_x() > 600)                                      /* go left*/
  18.             drive (180,100);
  19.        while (loc_x() > 560)
  20.             drive (180,50);
  21.        drive(180,0);                                                /* stop */
  22.       }
  23. if (loc_y()<500)
  24.   {
  25.    while (loc_y() < 400)
  26.         drive (90,100);                                    /* goto y center */
  27.    while (loc_y() < 440)
  28.         drive (90,50);
  29.    drive (0,0);                                                     /* stop */
  30.   }
  31.   else                                       /* if robot is above of center */
  32.       {
  33.        while (loc_y() > 600)
  34.             drive (270,100);                                     /* go down */
  35.        while (loc_y() > 560)
  36.             drive (270,50);
  37.        drive(270,0);                                                /* stop */
  38.       }
  39.                         /* Now the robot should be very close to the center */
  40. while (1)                                                  /* infinite loop */
  41.  dam=damage();
  42.  while (damage()-3 < dam)               /* while robot is not taking damage */
  43.       {
  44.        fire (37);
  45.        fire (45);                             /* fire in upper right corner */
  46.        fire (53);
  47.        fire (127);
  48.        fire (135);                             /* fire in upper left corner */
  49.        fire (143);
  50.        fire (217);
  51.        fire (225);                             /* fire in lower left corner */
  52.        fire (233);
  53.        fire (307);
  54.        fire (315);                            /* fire in lower right corner */
  55.        fire (325);
  56.       }                                                        /* end while */
  57.  while (loc_x() < 600)                             /* dodge by moving right */
  58.       drive (0,100);
  59.  while (speed() > 0)
  60.       drive (0,0);
  61.  while (loc_x() > 560)
  62.       drive (180,100);                                          /* recenter */
  63.  while (loc_x() > 530)
  64.       drive (180,50);
  65.  drive(180,0);                                                      /* stop */
  66. }                                                      /* end infinite loop */
  67. }                                                               /* end main */
  68. fire (dir)
  69. int dir;
  70. {int
  71.      range,
  72.      exact, /* percision of scanner */
  73.      dam;
  74. exact=10;
  75. range=scan(dir,exact);
  76. dam=damage();
  77. while ((range > 1) && (damage()-1 < dam))
  78.      {
  79.       if (exact > 1)
  80.         --exact;                                         /* decrement exact */
  81.       if (exact = 0)
  82.         cannon (0,0);
  83.       if ((scan(dir,exact)==0) && (scan(dir,exact+1) > 0))
  84.         dir=dir+1;
  85.       if (scan(dir,exact)==0)
  86.         dir=dir-2;
  87.       range=scan(dir,exact);
  88.       if ((range > 50) && (range < 750))
  89.         cannon(dir,range);
  90.      }
  91. return;
  92. } /* end fire */
  93.